<?php
switch($engineReturn['record']['type'])
{
	case "data":
		switch($engineReturn['record']['mode'])
		{
			case "ins":
				$this->load->view("engine/module/sub_input_insert.php", array("engineReturn"=>$engineReturn));
			break;
			case "edt":
				$this->load->view("engine/module/sub_input_edit.php", array("engineReturn"=>$engineReturn));
			break;
			case "nav":
			default:
				$this->load->view("engine/module/sub_input_grid.php", array("engineReturn"=>$engineReturn));
			break;
		}
	break;
	case "all":
	default:
		echo "<div id='divIdSub' style='display:none'>";
		$res	= $engineReturn['record']['master'][0];
		echo "</table>";
		echo "<table class='table'>";
		echo "<tr>";
			foreach($engineReturn['record']['fieldSetting'] as $i=>$v)
			{
				if($v['view'])
				{
					switch($v['input'])
					{
						case "medium_table":
						case "advance_table":
							$rs = count($res[0][$v['name']][1]);
							echo "<th colspan='".$rs."'>";
								echo $v['text'];
							echo "</th>";
						break;
						default:
							echo "<th rowspan='2'>";
								echo $v['text'];
							echo "</th>";
						break;
					}
				}
			}
		echo "</tr>";
		echo "<tr>";
			foreach($engineReturn['record']['fieldSetting'] as $i=>$v)
			{
				if($v['view'])
				{
					switch($v['input'])
					{
						case "medium_table":
						case "advance_table":
							foreach($res[0][$v['name']][1] as $fv)
							{
								echo "<th>";
									echo $fv;
								echo "</th>";
							}
						break;
						default:
						break;
					}
				}
			}
		echo "</tr>";
		for($i = 0; $i<count($res); $i++)
		{
			$id	= $res[$i][$engineReturn['record']['fieldSetting'][0]['name']];
			echo "<tr>";
				foreach($engineReturn['record']['fieldSetting'] as $v)
				{
					$fieldName	= $v['name'];
					if($v['view'])
					{
						switch($v['input'])
						{
							case "hidden":
							case "text":
							case "text_primary":
							case "password":
							case "text_area":
							case "text_area_plus_editor":
								echo "<td>";
								echo $res[$i][$fieldName];
							break;
							case "checkbox":
								echo "<td>";
								if(is_array($res[$i][$fieldName]))
								{
									foreach($res[$i][$fieldName] as $v)
									{
										echo $v.", ";
									}
								}
							break;
							case "image":
								echo "<td>";
								if($res[$i][$fieldName]!="")
									echo "<div class='defContainerImage'>"
										."<img src='".$res[$i][$fieldName]."'>"
										."</div>";
							break;
							case "file":
								echo "<td>";
								if($res[$i][$fieldName]!="")
									echo "<a href='".$res[$i][$fieldName]."' target='_SELF'>"
										."DOWNLOAD</a>";
							break;
							case "radio":
							case "select":
								echo "<td>";
								if(isset($res[$i][$fieldName][1]))
									echo $res[$i][$fieldName][1];
								else
									echo $res[$i][$fieldName][0];
							break;
							case "simple_table":
								echo "<td>";
								if(isset($res[$i][$fieldName]['dataRec']))
									echo $res[$i][$fieldName]['dataRec'];
								else
									echo "-";
							break;
							case "medium_table":
							case "advance_table":
								$rs = count($res[$i][$fieldName][1]);
									if(isset($res[$i][$fieldName][0][0]) && (is_array($res[$i][$fieldName][0][0])))
									{
											foreach($res[$i][$fieldName][0][0] as $t)
											{
												echo "<td>".$t."</td>";
											}
									}
									else
									{
										echo "<td colspan='$rs'>";
									}
							break;
						}
						echo "</td>";
					}
				}
			echo "</tr>";
		}
		echo "</table>";
		echo "<b>Sub Data</b><p></p>";
		echo "<div id='containerGrid'>";
			$this->load->view("engine/module/sub_input_grid.php", array("engineReturn"=>$engineReturn));
		echo "</div>";
		echo "</div>";
		echo "<script type='text/javascript'>
				$('#divIdSub').delay(100).slideDown('slow');
			</script>";
	break;
}
?>
